const db = uniCloud.database();
const dbCmd = db.command;
const collection = db.collection('class_table');

const getTypeList = async (data) => {
	try {
		const res = await collection.where(data).get()
		return res
	} catch (e) {
		//TODO handle the exception
	}
}

const updateTypeList = async (params) => {
	try {
		const {type, data} = params || {};
		if(!type) return;
		const res = await collection.where({totalType:type}).update(data)
		return res
	} catch (e) {
		//TODO handle the exception
	}
}

exports.main = async (event, context) => {
	console.log('event', event);
	const {
		action,
		params
	} = event || {}
	switch (action) {
		case 'getTypeList':
			return await getTypeList(params);
			break;
		case 'updateTypeList':
			return await updateTypeList(params);
			break;
		default:
			return await getTypeList(params);
			break;
	}
};